package Yangtz.Cs.Reader.Controller.PesonalCenter;

import Yangtz.Cs.Service.ReaderService;
import Yangtz.Cs.Utils.DataTransmissionUtil;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ChangeInfoServlet")
public class ChangeInfoServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        JSONObject jsonObject= DataTransmissionUtil.gainJsonFromAndroid(request);
        ReaderService rs=new ReaderService();

        JSONObject jsonObject1=new JSONObject();
        //更新成功就返回true,并返回安卓一个success的tag
        if(rs.ChangeINfo(jsonObject)){
            jsonObject1.put("ch_tag","success");
        }else{
            jsonObject1.put("ch-tag","failed");
        }
        DataTransmissionUtil.sendJsonToAndroid(jsonObject1,response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
